import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ASUS
 * Date: 2022-07-30
 * Time: 18:48
 */
public class WorkTest {
    //在同一个类中定义多个方法：要求不仅可以求2个整数的最大值，还可以求3个小数的最大值？
    public static void cmp(int a,int b){
        System.out.println((a > b)? a : b);
    }
    public  static  void cmp(double a,double b,double c){
        double s = (a > b) ? a : b;
        double t = (b > c) ? b : c;
        System.out.println((s > t)?s : t);
    }


    public static void main(String[] args) {
        int x = 5;
        int y = 8;
        cmp(x , y);
        double p = 2.6;
        double q = 5.3;
        double r = 8.9;
        cmp(p , q , r);

    }


    //在同一个类中,分别定义求两个整数的方法和三个小数之和的方法。 并执行代码，求出结果
    public  static int add(int a,int b){
        return  a + b;
    }

    public static  double add(double a,double b ,double c){
        return  (a + b + c);
    }

    public static void main4(String[] args) {
        int x = 12;
        int y = 20;
        int sum = add(x,y);
        System.out.println(sum);
        double o = 5.6;
        double p = 9.2;
        double q = 1.1;
        double sum1 = add(o , p , q);
        System.out.println(sum1);

    }



    //求斐波那契数列的第n项。(迭代实现)

    public static int fib(int n){

            if(n == 1 ||n ==2) {
                return 1;
            }else {
                return(fib(n-1)+fib(n-2));
            }
    }

    public static void main3(String[] args) {

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个数：");
        int n = sc.nextInt();
        int sum = fib(n);
        System.out.println(sum);
    }



    //求 N 的阶乘和
   public static int facsum(int n){
       int sum = 0;
       for (int i = 1; i <= n ; i++) {
           int ret = fac(i);
           sum += ret;
       }
       return sum;
   }
    public static int  fac(int n){
        int ret = 1;
        for (int i = 1; i <= n ; i++) {
            ret *= i;
        }
        return ret;

    }

    public static void main2(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个数：");
        int n = sc.nextInt();
        int sum = facsum(n);
        System.out.println(sum);
    }


    //创建方法求两个数的最大值max2，随后再写一个求3个数的最大值的函数max3。
    //要求：在max3这个函数中，调用max2函数，来实现3个数的最大值计算

    public  static int compare1(int a,int b){
        return((a > b) ? a : b);
    }
    public  static  int compare(int a,int b,int c){
        int m =compare1(a , b);
        int n =compare1(b , c);
        return ((m > n)? m : n);
    }

    public static void main1(String[] args) {
        int x = 28;
        int y = -4;
        int z = 48;
        int max3 = compare(x,y,z);
        System.out.println(max3);
    }

}
